<template>
  <span>{{ getData(citys, 0) }}</span>
</template>

<script setup name="AddressInfo">
import citys from "@/assets/js/city.js";
import _ from "lodash";

const props = defineProps({
  data: {
    type: Array,
    default: function () {
      return [];
    },
  },
});

const state = {
  citys,
};
const getData = (citys, n) => {
  let address = "";
  let data = props.data;
  if (citys.length <= 0 || n >= data.length) return;
  let index = _.findIndex(citys, function (o) {
    return o.value === data[n];
  });
  if (index !== -1) {
    address += citys[index].label;
    if (citys[index]["children"]) {
      address += getData(citys[index]["children"], n + 1);
    }
  }
  return address;
};
</script>

<style scoped></style>
